home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWODExce / FWODFExc.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.9 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWODFExc.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWODFEXC_H
  11. #define FWODFEXC_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef FWEXCLIB_H
  18. #include "FWExcLib.h"
  19. #endif
  20.  
  21. #include <som.xh>
  22.  
  23. //========================================================================================
  24. // Forward declarations
  25. //========================================================================================
  26.  
  27. class FW_XException;
  28.  
  29. //========================================================================================
  30. // Global functions
  31. //========================================================================================
  32.  
  33. void FW_Failure(FW_PlatformError error);
  34. void FW_FailOnError(FW_PlatformError error);
  35. void FW_FailOnEvError(Environment* ev);
  36. void FW_SetEvError(Environment* ev, FW_PlatformError error);
  37. void FW_SetException(Environment *ev, const FW_XException& exception);
  38. FW_PlatformError FW_GetEvError(Environment* ev);
  39.  
  40. //========================================================================================
  41. //    CLASS FW_XException
  42. //========================================================================================
  43.  
  44. class FW_XException
  45. {
  46. public:
  47.     FW_DECLARE_EXCEPTION(FW_XException)
  48.  
  49.     virtual ~FW_XException();
  50.     FW_XException(const FW_XException& exception);
  51.     FW_XException(FW_PlatformError theError);
  52.  
  53.     FW_PlatformError GetPlatformError() const;
  54.  
  55. private:
  56.     const FW_PlatformError fPlatformError;
  57. };
  58.  
  59. //========================================================================================
  60. // Macros
  61. //========================================================================================
  62.  
  63. #ifdef SOMCHKEXCEPT
  64. #undef SOMCHKEXCEPT
  65. #endif
  66.  
  67. #define SOMCHKEXCEPT ::FW_FailOnEvError(ev)
  68.  
  69. // The following two macros are to be used in SOM methods that call C++ code that may throw.
  70. //    Because we can't throw C++ exceptions from a SOM method (this would really toast things)
  71. //    we have to make sure that any exception that may be thrown is caught and converted into
  72. //    an error code and stored in the "ev" parameter.
  73. //
  74. //    SOM_Scope long  SOMLINK FW_OSomeClassSomeMethod(FW_OSomeClass *somSelf, Environment *ev)
  75. //    {
  76. //        ... usual SOM prologue ...
  77. //        FW_SOM_TRY
  78. //        {
  79. //            A_Cxx_function_that_may_throw();
  80. //        }
  81. //        FW_SOM_CATCH
  82. //    }
  83. //
  84.  
  85. #define FW_SOM_TRY    \
  86.     FW_TRY
  87.  
  88. #define FW_SOM_CATCH \
  89.     FW_CATCH_BEGIN \
  90.     FW_CATCH_REFERENCE(FW_XException, exception) \
  91.     { \
  92.         FW_SetException(ev, exception); \
  93.     } \
  94.     FW_CATCH_EVERYTHING() \
  95.     { \
  96.         FW_SetEvError(ev, FW_xUnknownError); \
  97.     } \
  98.     FW_CATCH_END
  99.     
  100. // The following two macros are a variation on the above except exceptions are caught and
  101. //    then gracefully dropped on the floor.  This is for somUninit() method - if something
  102. //    goes wrong in the destructor, there is not much that can be done.  Besides, somUninit
  103. //    does not have an "ev" pointer
  104.  
  105. #define FW_SOM_UNINIT_TRY    \
  106.     FW_TRY
  107.  
  108. #define FW_SOM_UNINIT_CATCH \
  109.     FW_CATCH_BEGIN \
  110.     FW_CATCH_EVERYTHING() \
  111.     { \
  112.     } \
  113.     FW_CATCH_END
  114.  
  115. // The following two macros are another variation on the above.
  116. // This time, we assume that a FW_PlatformError will be set intead of an Environment.
  117.  
  118. #define FW_ERR_TRY    \
  119.         *error = FW_xNoError;    \
  120.         FW_TRY
  121.  
  122. #define FW_ERR_CATCH    \
  123.     FW_CATCH_BEGIN         \
  124.     FW_CATCH_REFERENCE(FW_XException, exception) \
  125.     { \
  126.         *error = exception.GetPlatformError(); \
  127.     } \
  128.     FW_CATCH_EVERYTHING() \
  129.     { \
  130.         *error = FW_xUnknownError; \
  131.     } \
  132.     FW_CATCH_END
  133.  
  134. #define FW_RETURN_ERR_TRY    \
  135.         FW_PlatformError error = FW_xNoError;    \
  136.         FW_TRY
  137.  
  138. #define FW_RETURN_ERR_CATCH    \
  139.     FW_CATCH_BEGIN         \
  140.     FW_CATCH_REFERENCE(FW_XException, exception) \
  141.     { \
  142.         error = exception.GetPlatformError(); \
  143.     } \
  144.     FW_CATCH_EVERYTHING() \
  145.     { \
  146.         error = FW_xUnknownError; \
  147.     } \
  148.     FW_CATCH_END \
  149.     return error;
  150.  
  151. #endif
  152.